home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / igps_102.zip / PHONEVW.H < prev    next >
C/C++ Source or Header  |  1994-11-30  |  6KB  |  173 lines

  1. ////////////////////////////////////////////////////////////////////////////////////
  2. // Internet Global Phone Project
  3. // phonevw.h : interface of the CPhoneView class                             
  4. //
  5. // The Phoneview class is responsible for user interface handling and low level 
  6. // audio handling (including compression/decompression via GSM).
  7. //
  8. ////////////////////////////////////////////////////////////////////////////////////
  9. // Copyright (c) 1993-1994    microWonders Inc.  All rights reserved.
  10. //                                                                         
  11. // AN OPEN INVITION TO BUILD UPON AND CONTRIBUTE TO THE PUBLIC TECHNOLOGY POOL:
  12. // You are encouraged to redistribute, and build upon the technologies presented 
  13. // in this source module and the accompanying article in Dr. Dobb's Journal provided 
  14. // all the conditions listed in the MUSTREAD.TXT file, included with this 
  15. // distribution, are met.
  16. ////////////////////////////////////////////////////////////////////////////////////
  17.  
  18. #include "mmsystem.h"                                          
  19. #include "gsm.h"
  20.  
  21. //
  22. // To enable 16 bit sound record and playback, uncomment the following two defines.
  23. // Note it is also possible (although there's almost no reason to) enable assymetrical
  24. //  sampling/playback sample widths.
  25. //                          
  26. // 16 bits input sampling                       
  27. //#define HIGH_FIDELITY   
  28. // 16 bits output 
  29. //#define HIGH_FI_OUT
  30.  
  31. // an out of memory error, specific to IGP
  32. #define IGP_NOMEM        1
  33.  
  34. // custom messages to signify completing of recording and compression
  35. #define    PHONEMSG_RECORD_DONE    WM_USER+100 
  36. #define PHONEMSG_COMPRESS_DONE    WM_USER+102                          
  37.  
  38. // various buffer size definitions
  39. #define PHONE_WAVEIN_BUFSIZE    12000L
  40. #define PHONE_WAVEOUT_BUFSIZE    12000L  // ** must be multiple of GSM_FRAME_SIZE
  41. #define COMPRESSED_BUFSIZE        200000L 
  42. #define GSM_FRAME_SIZE            160  
  43.                               
  44. // Ports to listen/connect                              
  45. // IGP_PORT is compatible with UNIX current atalk and mtalk utilities
  46. // IGP_P2 is used in testing. By dovtailing StartListener() and Connect() port numbers,
  47. //
  48. //   and creating two mphones, one can do testing on a loopback.
  49. //
  50. #define IGP_PORT    5101      
  51. #define IGP_P2        5104
  52.  
  53. /*
  54.  * Data Types
  55.  */
  56. typedef struct waveInst {
  57.     HANDLE hWaveInst;
  58.     HANDLE hWaveHdr;
  59.     HANDLE hWaveData;
  60.     BOOL LastBlock;
  61. } WAVEINST;
  62.  
  63.  
  64. typedef WAVEINST FAR *LPWAVEINST;   
  65. typedef struct threadState{  
  66. ULONG        maxIter;
  67. ULONG        linearCount;
  68. ULONG        i;
  69. LPWAVEHDR    lpWaveHdr;
  70. HPSTR        lpData;  
  71. BOOL        doneBuffer;
  72. } TSTATE;     
  73.  
  74. typedef struct dthrdState{
  75. ULONG    linear;
  76. UINT    b;
  77. HPSTR    CompressedBuf;
  78. ULONG    CompBufSize;
  79. ULONG    i;
  80. LPWAVEHDR lpWaveHdr; 
  81. LPWAVEINST lpWaveInst;
  82. HPSTR lpData;
  83. } DTSTATE;
  84.  
  85. typedef TSTATE FAR *LPTSTATE;
  86. class CPhoneView : public CEditView
  87. {
  88. protected: // create from serialization only
  89.     CPhoneView();
  90.     DECLARE_DYNCREATE(CPhoneView)
  91.  
  92. // Attributes
  93. public:
  94.     CPhoneDoc* GetDocument();  
  95.  
  96. protected:
  97.     BOOL m_recording; 
  98.     BOOL m_transmitting; 
  99.     BOOL m_compressing;  
  100.     
  101.     BOOL m_compressWork;
  102.     BOOL m_decompressWork;
  103.     
  104.     HWAVEIN m_hWaveIn; 
  105.     HWAVEOUT m_hWaveOut; 
  106.     CDWordArray  m_bufList;
  107.     gsm m_hGsm;
  108.     gsm_frame m_GsmBuf;
  109.     gsm_signal m_sample[GSM_FRAME_SIZE]; 
  110.     
  111.     HGLOBAL m_hCompress;
  112.     HGLOBAL m_hspeechBuffer;
  113.     HPSTR m_CompressedBuf;
  114.     unsigned long m_CompBufSize;
  115.     
  116.     TSTATE    m_state;  // background thread states variables    
  117.     DTSTATE m_dstate;  // background decompression thread states
  118.     // Sockets                  
  119.     BOOL m_ListenerStarted;
  120.     CTalkListenServer m_TalkListener;
  121.     CTalkClient m_TalkClient;  
  122.     WSADDRESS m_ClientAddress; 
  123.     WSADDRESS m_ListenerAddress;
  124.  
  125. // Operations
  126. public:
  127.     LRESULT ExpandWaveOut(HGLOBAL hMem, HPSTR buffer, ULONG bufLength);    
  128. // Implementation
  129. public:
  130.     virtual ~CPhoneView();
  131.     virtual void OnDraw(CDC* pDC);  // overridden to draw this view
  132. #ifdef _DEBUG
  133.     virtual void AssertValid() const;
  134.     virtual void Dump(CDumpContext& dc) const;
  135. #endif
  136.  
  137.       
  138.     BOOL DoIdleProcessing(void);   // this is the idle loop backgroup process
  139. protected:
  140.     BOOL MakeWaveInBuffer( HWAVEIN hWaveIn, LPWAVEHDR &newBuf, DWORD dwBufSize);  // Create a New buffer
  141.     BOOL MakeWaveOutBuffer(HWAVEIN hWaveIn, HWAVEOUT hWaveOut, LPWAVEHDR &newBuf, DWORD dwBufSize); 
  142.     BOOL DestroyWaveInBuffer(HWAVEIN hWaveIn, LPWAVEHDR oldBuf);   
  143.     BOOL DestroyWaveOutBuffer(HWAVEOUT hWaveOut, LPWAVEHDR oldBuf); 
  144.     LRESULT CompressPartialBuffer(LPTSTATE state);
  145.     LRESULT PlayWaveInBuffer(LPWAVEHDR); 
  146.     LRESULT CompressABuffer(HPSTR lpData, DWORD lsize);  
  147.     void AddOut(LPSTR,  UINT);
  148. // Generated message map functions
  149. protected:
  150.     //{{AFX_MSG(CPhoneView) 
  151.     afx_msg LRESULT OnWaveInClose(WPARAM wParam, LPARAM lParam);
  152.     afx_msg LRESULT OnWaveInOpen(WPARAM wParam, LPARAM lParam);
  153.     afx_msg LRESULT OnWaveInData(WPARAM wParam, LPARAM lParam);    
  154.     afx_msg LRESULT OnWaveOutDone(WPARAM wParam, LPARAM lParam);
  155.     afx_msg LRESULT OnRecordDone(WPARAM wParam, LPARAM lParam); 
  156.     afx_msg LRESULT OnCompressDone(WPARAM wParam, LPARAM lParam);
  157.     afx_msg LRESULT OnClientNotify(WPARAM wParam, LPARAM lParam);
  158.     afx_msg void OnUpdatePhRecord(CCmdUI* pCmdUI);
  159.     afx_msg void OnUpdatePhSend(CCmdUI* pCmdUI);
  160.     afx_msg void OnPhRecord();
  161.     afx_msg void OnPhSend();
  162.     afx_msg void OnFileOpen();
  163.     //}}AFX_MSG
  164.     DECLARE_MESSAGE_MAP()
  165. };
  166.  
  167. #ifndef _DEBUG  // debug version in phonevw.cpp
  168. inline CPhoneDoc* CPhoneView::GetDocument()
  169.    { return (CPhoneDoc*)m_pDocument; }
  170. #endif
  171.  
  172. /////////////////////////////////////////////////////////////////////////////
  173.